package session.servlet;

import session.entity.Cake;
import session.entity.CakeDB;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;

@WebServlet(name = "ListCakeServelt", value = "/cake-list")
public class ListCakeServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        Collection<Cake> all = CakeDB.getAll();
        PrintWriter w = response.getWriter();
        w.write("所有的蛋糕：<br>");
        for (Cake cake : all) {
            String url = "/cake-purchase?id=" + cake.getId();
            w.write( cake.getName() + "<a href='"+url+"'>点击购买</a><br>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
